package com.practice.blog.controller;

import com.practice.blog.common.pojo.request.UserLoginParam;
import com.practice.blog.common.pojo.response.UserInfoResponse;
import com.practice.blog.common.pojo.response.UserLoginResponse;
import com.practice.blog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-30
 * Time: 19:27
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;

    @RequestMapping("/login")
    public UserLoginResponse userLogin(@Validated @RequestBody UserLoginParam userParam) {//Validated对全体实体类校验
        log.info("用户名: ",userParam.getUserName());
        return  userService.login(userParam);
    }

    @RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfoById(@NotNull Integer userId) {
        log.info("获取用户信息，用户Id: {}",userId);
        return userService.getUserInfoById(userId);
    }

    @RequestMapping("/getAuthorInfo")
        public UserInfoResponse getAuthorInfo(@NotNull Integer blogId) {
        log.info("获取作者信息，blogId: {}",blogId);
        return userService.getAuthorInfoById(blogId);
    }
}
